package de.karlNet.sambamanager.view.beans;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapController.commands.RemoveUserFromGroup;
import de.karlNet.sambamanager.ldapModel.LdapGroup;
import de.karlNet.sambamanager.ldapModel.LdapUser;
import de.karlNet.sambamanager.view.beans.trees.SelectedNodeContainer;

@Controller
@Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS)
public class RemoveUserFromGroupBean {
	@Autowired
	private SelectedNodeContainer selectedNodeContainer;

	public void removeFromGroup() {
		LdapUser ldapUser = (LdapUser) this.selectedNodeContainer.selectedNode
				.getLdapObject();
		LdapGroup ldapGroup = (LdapGroup) ((ManualLeafHandlingTreeNode) this.selectedNodeContainer.selectedNode
				.getParent()).getLdapObject();
		new RemoveUserFromGroup()
				.removeUserFromGroupItself(ldapGroup, ldapUser);
		this.selectedNodeContainer.selectedNode.setParent(null);
	}
}
